package medium字母异位分词组;

import org.testng.annotations.Test;

import java.util.*;

public class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> list = new ArrayList<>();
        HashMap<String ,List<String>> map = new HashMap<>();
        for (String s:
                strs) {
            char[] chars = s.toCharArray();
            Arrays.sort(chars);
            map.put(String.valueOf(chars),new ArrayList<>());
        }
        for (String s:
                strs) {
            char[] chars = s.toCharArray();
            Arrays.sort(chars);
            map.get(String.valueOf(chars)).add(s);
        }
        Set<String > set = map.keySet();
        for (String s:
                set) {
            list.add(map.get(s));
        }
//        for (List<String> lst:
//             list) {
//            System.out.println(lst.toString());;
//        }
        return list;
    }
    @Test
    public void test(){
        String[] s = {"eat", "tea", "tan", "ate", "nat", "bat"};
        groupAnagrams(s);
    }
}
